// const express = require('express')
// const app = express()

// app.get('/', (req, res) => {
//   res.send('你好')
// })

// app.listen(3000, () => console.log('服务器已就绪'))

var http = require('http');
var fs = require("fs");
http.createServer(function (request, response) {
    var url0 = "www.baidu.com"
    var url1 = fs.readFileSync('test.html', 'utf-8')
    var url2 = fs.readFileSync('test2.html', 'utf-8')
    var url3 = fs.readFileSync('testimg.png')
    
    console.log(request.url)

    var url = request.url
    // response.writeHead(200, {'Content-Type': 'text/plain;charset=utf-8'});  
    if (url == "/test1") {
        response.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        });
        response.end(url1);
    } else if (url == "/") {
        response.writeHead(200, {
            'Content-Type': 'text/plain;charset=utf-8'
        });
        response.end(url1);
    } 
    // else if (url == "/testimg.png") {
    //     response.writeHead(200, {
    //         'Content-Type': 'text/png;charset=utf-8'
    //     });
    //     response.end(url3);
    // } 
    else if (url == "/stream") {
        response.writeHead(200, {
            'Content-Type': 'application/octet-stream'
        });
        response.end(url1);
    } 
    else if (url == "/img") {
        response.writeHead(200, {
            'Content-Type': 'application/octet-stream'
        });
        response.end(url3);
    } 
    else {
        response.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        });
        response.end(url2);
    }

}).listen(8899);
console.log('Server running at http://127.0.0.1:8899/');